<?php
App::import("Model", "ImageProduct");
$model = new ImageProduct();
//$model->find("list");
 //var_dump($images);die;
 ?>
 <style type="text/css" media="screen">
     td img {
         width: 80px;
     }
 </style>
<div class="box round first">
    <h2><?php echo __('Products'); ?></h2>
<div class="products index block">
    <table cellpadding="0" cellspacing="0">
    <tr>
            <th><?php echo $this->Paginator->sort('id'); ?></th>
            <th>Image</th>
            <th><?php echo $this->Paginator->sort('code'); ?></th>
            <th><?php echo $this->Paginator->sort('name'); ?></th>
            <th><?php echo $this->Paginator->sort('provider_id'); ?></th>
            <th><?php echo $this->Paginator->sort('category_id'); ?></th>
            <th><?php echo $this->Paginator->sort('price'); ?></th>
            <th><?php echo $this->Paginator->sort('rate'); ?></th>
            <th><?php echo $this->Paginator->sort('describe'); ?></th>
            <th><?php echo $this->Paginator->sort('modified'); ?></th>
            <th class="actions"><?php echo __('Actions'); ?></th>
    </tr>
    <?php foreach ($products as $product): ?>
    <tr>
        <td><?php echo h($product['Product']['id']); ?>&nbsp;</td>
        <td><?php
        $images = $model->findAllByProductId($product['Product']['id'], array('fields' => 'Image.link' ));
        echo $this->Html->image($images[0]['Image']['link'], array('alt' => $product['Product']['name']));
        //debug($image);
         ?> </td>
        <td><?php echo h($product['Product']['code']); ?>&nbsp;</td>
        <td><?php echo h($product['Product']['name']); ?>&nbsp;</td>
        <td>
            <?php echo $this->Html->link($product['Provider']['name'], array('controller' => 'providers', 'action' => 'view', $product['Provider']['id'])); ?>
        </td>
        <td>
            <?php echo $this->Html->link($product['Category']['title'], array('controller' => 'categories', 'action' => 'view', $product['Category']['id'])); ?>
        </td>
        <td><?php echo h($product['Product']['price']); ?>&nbsp;</td>
        <td><?php echo h($product['Product']['rate']); ?>&nbsp;</td>
        <td><?php echo h($product['Product']['describe']); ?>&nbsp;</td>
        <td><?php echo h($product['Product']['modified']); ?>&nbsp;</td>
        <td class="actions">
            <?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $product['Product']['id'])); ?>
            <?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $product['Product']['id']), null, __('Are you sure you want to delete # %s?', $product['Product']['id'])); ?>
        </td>
    </tr>
<?php endforeach; ?>
    </table>
    <p>
    <?php
    echo $this->Paginator->counter(array(
    'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
    ));
    ?>	</p>
    <div class="paging">
    <?php
        echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
        echo $this->Paginator->numbers(array('separator' => ''));
        echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
    ?>
    </div>
</div>

</div>
